package com.homework.homework6;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        //地主
        String diZhu = null;
        //定义一个存放牌的集合
        //定义数字数组
        //定义花色数组
        Collection<String> poke = new ArrayList<>();
        String[] colors = {"♠", "♥", "♣", "♦"};
        String[] numbers = {"K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2", "A"};
        //先把大王和小王存储到poker集合中
        poke.add("大王");
        poke.add("小王");
        for (String s : colors) {
            for (String number : numbers) {
                poke.add(number + s);
            }
        }
        System.out.println("生成牌-------------------------");
        int num = 0;
        for (String s : poke) {
            num++;
            if (num % 17 == 0) {
                System.out.println();
            }
            System.out.print(s + " ");
        }
        System.out.println();
        System.out.println("洗牌完毕-------------------------");
        Collections.shuffle((List<?>) poke);
        System.out.println();
        System.out.println("开始发牌---------------------------");
        //定义四个集合
        //定义4个集合,存储玩家的牌和底牌
        ArrayList<String> player01 = new ArrayList<String>();
        ArrayList<String> player02 = new ArrayList<String>();
        ArrayList<String> player03 = new ArrayList<String>();
        ArrayList<String> diPai = new ArrayList<String>();
        for (int i = 0; i < poke.size() ; i++) {
            //获取每一张牌
            String p = ((ArrayList<String>) poke).get(i);
            //轮流发牌
             /*
            遍历poker集合,获取每一张牌
            使用poker集合的索引%3给3个玩家轮流发牌
            剩余3张牌给底牌
            注意:
                先判断底牌(i>=51),否则牌就发没了
         */
            if(i>=51){      // 剩下三张做底牌
                //给底牌发牌
                diPai.add(p);
            }else if(i%3==0){
                //给玩家1发牌
                player01.add(p);
                if(p=="大王"){
                    diZhu= "player1";
                }
            }else if(i%3==1){
                //给玩家2发牌
                player02.add(p);
                if(p=="大王"){
                    diZhu = "player2";
                }
            }else if(i%3==2){
                //给玩家3发牌
                player03.add(p);
                if(p=="大王"){
                    diZhu = "player3";
                }
            }
        }
        if(diZhu=="player01"){
            setDipai(player01, diPai);
        }else if(diZhu=="player02"){
            setDipai(player02, diPai);
        }else{
            setDipai(player03, diPai);
        }

        //4.看牌
        System.out.println("玩家1:"+player01);
        System.out.println("玩家2:"+player02);
        System.out.println("玩家3:"+player03);
    }

    private static void setDipai(ArrayList<String> player01, ArrayList<String> diPai) {
        for (String s : diPai) {
            player01.add(s);
        }
    }
}
